<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\store\controller;

use app\api\model\CityModel;
use app\api\model\GradeModel;
use app\api\model\UserModel;
use library\Controller;
use think\Db;
use think\facade\Cache;

/**
 * 会议管理
 * Class FollowRecord
 * @package app\store\controller
 */
class Meeting extends Controller
{
    /**
     * 绑定数据表
     * @var string
     */
    protected $table = 'ah_meeting';

    /**
     * 会议列表
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index()
    {
        $this->title = '会议管理';
        $params = input();
        $where = [];
        #关键词搜索
        if (isset($params['keywords']) && $params['keywords'] != ''){

            $where[] = ['m.meeting_id|c.name|c.age', 'like',"%{$params['keywords']}%"];
        }

        #性别
        if (isset($params['sex']) && $params['sex'] != ''){

            $where[] = ['sex','eq',$params['sex']];
        }

        #添加时间
        if (isset($params['create_time']) && $params['create_time'] !== '') {
            $create_time = explode(' - ',$params['create_time']);
            $create_time1 = $create_time[1].' 23:59:59';
            $where[] = ['m.create_at','between',"{$create_time[0]},{$create_time1}"];
        }

        $query = $this->_query($this->table)->alias('m')
            ->join('ah_case c','m.case_id = c.id')
            ->where($where)->field('m.*,c.name,c.sex,c.age');

        $query->order('m.id desc')->page();
    }

    /**
     * 数据列表处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function _index_page_filter(&$data)
    {

        foreach ($data as &$v) {

            $v['meeting_at'] = $v['meeting_at'] != 0 ? date('Y-m-d H:i',$v['meeting_at']) : '';
            $nickname = UserModel::whereIn('id',$v['expert_ids'])->column('nickname');
            $v['nickname'] = implode(',',$nickname);
        }

    }


    /**
     * 表单数据处理
     * @param array $data
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    protected function _form_filter(&$data)
    {

    }

    /**
     * 表单结果处理
     * @param boolean $result
     */
    protected function _form_result($result)
    {
        if ($result && $this->request->isPost()) {
            $this->success('操作成功！', 'javascript:history.back()');
        }
    }


}
